// pages/set/set.js
const app = getApp()
var util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    form_data:{device:2},
    phone: '',
    placeholder:'请输入手机号',
    yzmCode: 30,
    password: '',
    password2: '',
    getCode: "1",
    login_timer: false
  },bindinput:function(e){
      util.bindinput(e,this);
  },onConfirm(){
      var data = this.data.form_data
      app.https_request(util.web_url.mobile_login,data,'POST',false,false,this,getCurrentPages()).then( (res)=>{
       
        if(res.code == 1){
          app.msg(res.msg)
          var token = app.globalData.token= res.data.userinfo.token
          wx.setStorageSync('token', token)
          wx.setStorageSync('userinfo', res.data.userinfo)
          getApp().globalData.token = token
         setTimeout(function(){
          wx.switchTab({
            url: '/pages/file/file',
          })
         },500)
        }else{
          app.msg(res.msg)
        }
        }).catch( (errMsg)=>{});
  },
  //获取验证码
  getCode: function() { //发送验证码按钮
    var mobile = this.data.form_data.mobile
    console.log(mobile)
    if(!mobile){
      app.msg('请输入正确的手机号',);return;
    }
    var that = this;
    var yzmCode = that.data.yzmCode;
    if(that.data.login_timer) return;
    that.setData({login_timer: true,getCode: "3"})
    let timer = setInterval(() => {
      yzmCode--;
      that.setData({
        yzmCode
      })
      if(yzmCode=== -1){
        clearInterval(timer);
        that.setData({
          getCode: "2",
          yzmCode: 60,
          login_timer: false
        })
      }
    },1000)
    
    app.https_request(util.web_url.get_code,{mobile:mobile,event:'mobilelogin'},'POST',false,false,this,getCurrentPages()).then( (res)=>{
     
      }).catch( (errMsg)=>{});
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})